//
//  XDHomeworkViewController.m
//  XDEducation
//
//  Created by apple on 2017/4/28.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDHomeworkViewController.h"
#import "XDHomeworkHeaderView.h"
#import "WebViewController.h"

@interface XDHomeworkViewController ()
/** 数据源 */
@property(nonatomic,strong) NSArray *dataArr;

@property (nonatomic,assign) NSInteger HeaderIndex;
@end

@implementation XDHomeworkViewController

-(void)viewDidLoad{

    [super viewDidLoad];
    
//    self.tableView.frame = CGRectMake(0, 0, ScreenW, ScreenH - 64);
}


-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSArray arrayWithObjects:
                    @"语文",
                    @"数学",
                    @"英语",
                    nil];
    }
    return _dataArr;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 60 * ScaleHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    XDHomeworkHeaderView *headerView  = [[XDHomeworkHeaderView alloc]init];
    headerView.ClickHeaderButton = ^(NSInteger Index)
    {
        self.HeaderIndex = Index;
    };
    return headerView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50 * ScaleHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"homework";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.textLabel.text = self.dataArr[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.textColor = UIColorFromRGB(0x4c4c4c);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    WebViewController *Web = [[WebViewController alloc] init];
    NSString *UrlStr = [NSString stringWithFormat:@"make.do?action=makeHomework2&uid=%@&subjectid=%ld",[AccountTool shareAccountTool].currentAccount.uid,(self.HeaderIndex+1)];
    NSString *Name  = @"课外作业";
    Web.str = BaseURL(UrlStr);
    Web.nameTitle = Name;   
    [self.navigationController pushViewController:Web animated:YES];
    
}
@end
